<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="<%=basePath %>">
    <title>运动营养</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="../res/js/tools.js"></script>
    <script src="../res/layui/layui.js"></script>
    <script src="../../res/js/login_common.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        layui.use('laydate', function(){
            //layui时间方法，layui显示时间日期要调用此方法
            var laydate = layui.laydate;

            //常规用法
            laydate.render({
                elem: '#newsTimeS'

            });
            //常规用法
            laydate.render({
                elem: '#newsTimeE'
                ,type: 'datetime'
            });
        });
        $(function(){
            $("#seachTable").on("click",function(){
                //执行重载
                //带条件查询
                table2.reload({
                    url:'../../AtsSchemeActionNutrition/selectVague',
                    where: {
                        newsTitle: $("#newsTitle").val()

                    },
                    page: { curr: 1 }
                });
            })
        });

    </script>

    <style type="text/css">
        #seachDiv{
            width: 100%;

        }

        #seachDiv span{
            display: inline-block;

        }

        #divImg{
            position: absolute;
            top:30%;
            left:30%;
            z-index: 999;
            display: none ;


        }


    </style>
</head>

<div class="demoTable">
    搜索：
    <div class="layui-inline">
        <input class="layui-input" name="newsTitle" placeholder="查询名称" id="newsTitle" autocomplete="off">

    </div>


    <input type="button" id="seachTable" class="layui-btn layui-btn-normal" value="搜索" />
</div>
<table id="demo" lay-filter="test"></table>


<script>
    var table2 = null ;
    var table = null;
    layui.use('table', function(){
        table = layui.table;

        //第一个实例
        table2 =  table.render({
            elem: '#demo'
            ,id:'testReload'
            ,height: 550
            ,toolbar: '#toolbarDemo'
            ,url: '../../AtsSchemeActionNutrition/jurisdiction' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'schemeName', title: '方案名称', width:150}
                ,{field: 'year', title: '方案年度', width:120, sort: true}
                ,{field: 'month', title: '方案月份', width: 100}
                ,{field: 'schemeType', title: '方案类型', width: 180, sort: true}
                ,{field: 'exp', title: '说明,建议', width: 180, sort: true}
                ,{field: 'file1', title: '附件1',toolbar: '#file1', width:80}
                ,{field: 'file2', title: '附件2',toolbar: '#file2', width:80}
                ,{field: 'file3', title: '附件3',toolbar: '#file3', width:80}
                ,{field: 'readTime', title: '查看时间', width: 180, sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:400}
            ]]
        });

        //删除
        table.on('tool(test)', function(obj){
            var data = obj.data;//行数据
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('您真的要删除吗?', function(index){
                    obj.del();
                    layer.close(index);
                    //使用ajax进入后台删除数据库中的数据
                    var url = "../../AtsSchemeActionNutrition/delete";
                    var data$ = {schemeId:data.schemeId};
                    /*alert(data.schemeId);*/
                    $.post(url,data$,function(obj){
                        //提示
                        layer.msg(obj.msg);
                    },"json");
                });
            } else if(obj.event === 'edit'){

                var data = obj.data;//行数据

                //iframe层
                layer.open({
                    type: 2,
                    title: '运动营养方案修改页面',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/NutritionAddorUpdate.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }else if(obj.event === 'cha'){
                var data = obj.data;//行数据
                //iframe层
                layer.open({
                    type: 2,
                    title: '查看',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/MentalityAtsSchemeLook.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }else if (obj.event === 'feedback'){
                //iframe层
                layer.open({
                    type: 2,
                    title: '反馈',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/updateMentalityAtsScheme.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }else if(obj.event === 'apply'){
                //iframe层
                layer.open({
                    type: 2,
                    title: '申请专家咨询',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/MentalityAtsSchemeExpertAdd.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }else if(obj.event == 'audit'){
                //iframe层
                layer.open({
                    type: 2,
                    title: '审核',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/check.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }else if(obj.event == 'reply'){
                //iframe层
                layer.open({
                    type: 2,
                    title: '回复',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['80%', '80%'],
                    content: '../pages/reply.html?id='+data.schemeId, //iframe的url
                    end : function() {
                        table2.reload();
                    }
                });
            }


        });


        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'addBtn':
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '运动营养方案新增页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: '../pages/NutritionAddorUpdate.html', //iframe的url
                        end : function() {
                            table2.reload();
                        }
                    });
                    break;


                // 两张表批量删除
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定需要删除吗?', function(index){
                            var ids = "";
                            $.each(data,function(index,item){
                                ids+=item.schemeId+",";
                            })
                            var url = "../../AtsSchemeActionNutrition/deleteAll";
                            var datas ={ids:ids};
                            $.post(url,datas,function(obj){
                                if(obj.num==1){
                                    layer.msg(obj.msg,{
                                        icon:1,
                                        time:1000 //1秒关闭(如果不配置默认三秒)
                                    },function(){
                                        //刷新父页面
                                        parent.location.reload();
                                    });
                                }else{
                                    layer.msg(obj.msg);
                                }
                            },'json');
                        });
                    }
                    break;


            };
        });
    });
</script>




<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">

        <button class="layui-btn layui-btn-sm" lay-event="addBtn">新增</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除选中数据</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="cha">查看</a>
    {{# if(loginObj.manager.usType=="教练"){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="feedback">反馈</a>
    {{# if(d.auditState==10||d.auditState==20||d.auditState==30||d.auditState==40){ }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="apply">申请专家咨询</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="apply">申请专家咨询</a>
    {{# } }}
    {{# } }}
    {{# if(loginObj.manager.usType=="领导"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="audit">审核</a><!--领导审核 派发专家 必需由该专家回复-->
    {{# } }}
    {{# if(loginObj.manager.usType=="专家"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="reply">回复</a>
    {{# } }}

</script>

<!--<script type="text/html" id="titleTpl">
    <img src='../../{{d.file1}}' alt='显示图片' class='imgcss' onmouseover='showImg(this)'/>
</script>-->

<!--点击附件实现下载-->
<script type="text/html" id="file1">
    <a href="../../{{d.file1}}" class="layui-btn layui-btn-xs" onclick="dd('{{d.schemeId}}');">下载</a>
</script>

<script type="text/html" id="file2">
    <a href="../../{{d.file2}}" class="layui-btn layui-btn-xs"  onclick="dd('{{d.schemeId}}');">下载</a>
</script>

<script type="text/html" id="file3">
    <a href="../../{{d.file3}}" class="layui-btn layui-btn-xs" onclick="dd('{{d.schemeId}}');">下载</a>
</script>

<script>
    //是否查看  查看时间
    function dd(obj){
        var id = loginObj.manager.usWaiid;
        var url = "../../AtsSchemeActionNutrition/updateByAthleteId";
        var data = {id:id,schemeId:obj};
        $.post(url,data,function(obj){

        },"json");
    }


</script>

<!--<script type="text/html" id="switchTpl">
    &lt;!&ndash; 这里的 checked 的状态只是演示 &ndash;&gt;
    <input type="checkbox" name="sex" value="{{d.isRead}}" lay-skin="switch" lay-text="查看|未查看" lay-filter="sexDemo" {{ d.isRead == 1 ?  'checked' : '' }}>
</script>-->


</body>
</html>